package concurrency.chapter5;

/**
 * @author honway.liu
 * @date 2019-06-06 18:42
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 *
 * 生产者消费者
 */
public class ProducerConsumerVersion1 {

    private int resource = 0;

    public void producer() {
        System.out.println("P->" + (++resource));
    }

    public void consumer() {
        System.out.println("C->" + resource);
    }

    public static void main(String[] args) {
        /**
         * 生产者和消费者没有通讯, 导致生产者生产完,消费者可能消费的是老的数据,或者重复消费
         */
        ProducerConsumerVersion1 producerConsumerVersion1 = new ProducerConsumerVersion1();
        new Thread(producerConsumerVersion1::producer, "P").start();

        new Thread(producerConsumerVersion1::consumer, "C").start();
    }
}
